package com.chensf.studydemo.common

import android.content.Intent
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import androidx.navigation.Navigation
import androidx.navigation.findNavController
import androidx.navigation.fragment.NavHostFragment
import com.chensf.studydemo.R
import com.tencent.smtt.sdk.QbSdk
import com.tencent.smtt.sdk.ValueCallback
import kotlinx.android.synthetic.main.fragment_common.*

class CommonActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_common)
    }

    override fun supportNavigateUpTo(upIntent: Intent) {
        findNavController(R.id.nav_host_fragment).navigateUp()
    }
}

class CommonFragment : Fragment() {
    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        return inflater.inflate(R.layout.fragment_common, container, false)
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        button1.setOnClickListener {
            Navigation.findNavController(it).navigate(R.id.action_qq_map)
            button1.text="已跳转"
        }

        button6.setOnClickListener {
            NavHostFragment.findNavController(this).navigate(R.id.action_calendar_test)
        }

        button9.setOnClickListener {
            NavHostFragment.findNavController(this).navigate(R.id.action_stripeView_test)
        }

        button10.setOnClickListener {
            NavHostFragment.findNavController(this).navigate(R.id.action_bubble_layout_test)
        }

        button11.setOnClickListener {
            //                intent.setClass(this, CommonWebViewActivity.class);//文件通过微信接收下载名称一致即可
//                intent.putExtra("url", "/storage/emulated/0/testfiles/各种账号.xlsx");
//                intent.putExtra("isOpenFile", true);
//                startActivity(intent);
            QbSdk.openFileReader(requireActivity(), "/storage/emulated/0/tbstest1.docx", null,
                ValueCallback { s -> Log.e("foo", "onReceiveValue: $s") })
//            NavHostFragment.findNavController(this).navigate(R.id.action_file_preview_demo)
        }

        button12.setOnClickListener {
            NavHostFragment.findNavController(this).navigate(R.id.action_pop_menu_demo)
        }

        button13.setOnClickListener {
            NavHostFragment.findNavController(this).navigate(R.id.action_load_more_demo)
        }
        button15.setOnClickListener {
            NavHostFragment.findNavController(this).navigate(R.id.action_image_viewpager_demo)
        }

        button16.setOnClickListener {
            NavHostFragment.findNavController(this).navigate(R.id.action_avatar_demo)
        }
        button17.setOnClickListener {
            NavHostFragment.findNavController(this).navigate(R.id.action_record_demo)
        }
        button18.setOnClickListener {
            NavHostFragment.findNavController(this).navigate(R.id.action_file_browse_demo)
        }
        button19.setOnClickListener {
            checkbox.isChecked = !checkbox.isChecked
        }
        button20.setOnClickListener {
            NavHostFragment.findNavController(this).navigate(R.id.action_grid_image_demo)
        }
        checkbox.setOnCheckChangeListener { checkbox, check ->
            Log.e("foo", "OnCheckChangeListener: isPressed=${checkbox.isPressed}--check=$check")
        }
    }
}